@import '~element-ui/packages/theme-chalk/src/common/var';

.dify-chat {
  height: 100vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;

  // 移动端顶部导航栏
  .mobile-header {
    display: none;
    height: 56px;
    background-color: $--color-white;
    border-bottom: 1px solid $--border-color-lighter;
    padding: 0 16px;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    z-index: 1000;

    .mobile-header-left,
    .mobile-header-right {
      width: 48px;
      display: flex;
      align-items: center;
    }

    .mobile-header-center {
      flex: 1;
      text-align: center;

      .mobile-title {
        font-size: 16px;
        font-weight: 600;
        color: $--color-text-primary;
      }
    }

    .mobile-menu-btn,
    .mobile-new-chat-btn {
      padding: 8px;
      font-size: 18px;
      color: $--color-text-regular;

      &:hover {
        background-color: $--color-primary-light-9;
      }
    }
  }

  // 移动端抽屉样式
  .mobile-drawer {
    .drawer-content {
      height: 100%;
      display: flex;
      flex-direction: column;
      background-color: #f9fbff;

      .drawer-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px;
        border-bottom: 1px solid $--border-color-lighter;

        h2 {
          margin: 0;
          font-size: 18px;
          font-weight: 600;
          color: $--color-text-primary;
        }

        .drawer-close-btn {
          padding: 8px;
          font-size: 16px;
          color: $--color-text-regular;
        }
      }

      .drawer-new-chat {
        margin: 16px;
        color: #4d6bfe;
        background-color: rgb(219, 234, 254);
        cursor: pointer;
        height: 44px;
        border-radius: 14px;
        align-items: center;
        width: calc(100% - 32px);
        font-size: 16px;
        font-weight: 500;
        line-height: 20px;
        display: flex;
        padding: 0 16px;
        transition: background-color 0.2s ease;

        &:hover {
          background-color: #c6dcf8;
        }

        .keyboard-shortcut {
          display: inline-flex;
          align-items: center;
          justify-content: center;
          margin-left: auto;
          padding: 0 6px;
          height: 20px;
          font-size: 12px;
          color: #909399;
          background-color: #f5f7fa;
          border-radius: 4px;
          border: 1px solid #e4e7ed;
        }
      }

      .drawer-conversation-list {
        flex: 1;
        overflow-y: auto;
        padding: 0 16px 16px;
      }
    }
  }

  .dify-main {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: 100%;

    .sidebar-enter-active,
    .sidebar-leave-active {
      transition: all 0.3s ease;
    }

    .sidebar-enter,
    .sidebar-leave-to {
      opacity: 0;
      transform: translateX(-20px);
    }

    // 为新对话按钮添加专门的动画
    .sidebar-enter-active .new-chat,
    .sidebar-leave-active .new-chat {
      transition: all 0.3s ease 0.1s;
      /* 延迟0.1s开始动画 */
    }

    .sidebar-enter .new-chat,
    .sidebar-leave-to .new-chat {
      opacity: 0;
      transform: translateY(-10px);
    }

    // 为键盘快捷键添加动画
    .sidebar-enter-active .keyboard-shortcut,
    .sidebar-leave-active .keyboard-shortcut {
      transition: all 0.3s ease 0.15s;
      /* 延迟0.15s开始动画 */
    }

    .sidebar-enter .keyboard-shortcut,
    .sidebar-leave-to .keyboard-shortcut {
      opacity: 0;
      transform: scale(0.8);
    }

    .side-menu-collapsed {
      width: 68px;
      height: 100%;
      display: flex;
      flex-direction: column;
      background-color: #f9fbff;
      border-right: 1px solid $--border-color-lighter;
      transition: all 0.3s ease;

      .collapsed-header {
        height: 56px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 16px 0;
        border-bottom: 1px solid $--border-color-lighter;
      }

      .collapsed-new-chat {
        width: fit-content;
        height: fit-content;
        margin: 16px auto 0;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.2s ease;

        &:hover {
          background-color: $--color-primary-light-9;
          border-color: $--color-primary;
        }

        i {
          font-size: 16px;
          color: $--color-text-regular;
        }
      }
    }

    .side-menu {
      width: 260px;
      height: 100%;
      // background-color: $--color-primary-light-9;
      // border-right: 1px solid $--border-color-lighter;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      background: #f9fbff;
      border-right: 1px solid $--border-color-lighter;
      transition: all 0.3s ease;

      .side-header {
        flex-shrink: 0;
        padding: 16px;
        text-align: center;

        .side-action {
          display: flex;
          align-items: center;
          justify-content: space-between;
          margin-bottom: 16px;

          h2 {
            margin: 0;
            font-size: 18px;
            font-weight: 600;
            color: $--color-text-primary;
          }
        }

        .new-chat {
          --local-button: #dbeafe;
          --local-button-text: rgb(77, 107, 254);
          --local-button-hover: #c6dcf8;
          color: #4d6bfe;
          background-color: rgb(219, 234, 254);
          cursor: pointer;
          height: 44px;
          border-radius: 14px;
          flex-shrink: 0;
          align-items: center;
          width: 100%;
          font-size: 16px;
          font-weight: 500;
          line-height: 20px;
          display: flex;
          overflow: hidden;
          padding: 0 10px;
          white-space: nowrap;
          /* 防止文字换行 */
          opacity: 1;
          transition: opacity 0.3s ease, width 0.3s ease, padding 0.3s ease;

          .keyboard-shortcut {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            margin-left: 8px;
            padding: 0 6px;
            height: 20px;
            font-size: 12px;
            color: #909399;
            background-color: #f5f7fa;
            border-radius: 4px;
            border: 1px solid #e4e7ed;
            transition: opacity 0.3s ease;
          }
        }

        .new-chat-btn {
          width: 100%;
        }
      }

      .conversation-list {
        flex: 1;
        overflow-y: auto;
        padding: 8px;
        opacity: 1;
        transition: opacity 0.3s ease;
      }
    }

    // 通用的切换按钮样式
    .toggle-side {
      width: fit-content;
      height: fit-content;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      transition: background-color 0.2s ease;

      &:hover {
        background-color: rgba(0, 0, 0, 0.05);
      }

      i {
        font-size: 14px;
        color: $--color-text-regular;
      }
    }

    .chat-container {
      width: 100%;
      max-width: 800px;
      height: 100%;
      margin: auto;
      flex: 1;
      display: flex;
      flex-direction: column;
      background-color: $--color-white;

      .chat-header {
        height: 56px;
        min-width: 0px;
        display: flex;
        align-items: center;
        place-content: center;
        flex-shrink: 0;

        .chat-title:hover {
          box-shadow: inset 0 0 0 1px #0000001f;
        }

        .chat-title {
          cursor: pointer;
          white-space: nowrap;
          text-overflow: ellipsis;
          color: #262626;
          box-sizing: border-box;
          max-width: 100%;
          height: 40px;
          transition: box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1);
          border-radius: 12px;
          padding: 8px 12px;
          font-size: 14px;
          font-weight: 600;
          line-height: 24px;
          overflow: hidden;
        }

        h3 {
          margin: 0;
          font-size: 16px;
          color: $--color-text-primary;
        }
      }

      .chat-content {
        flex: 1;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        flex-shrink: 0;
        padding: 0 0 15px 0;

        .chat-content-welcome {
          width: 100%;
          margin: auto;
        }

        ::v-deep .el-x-bubble-list {
          .el-x-bubble {
            .el-x-bubble-content-wrapper {
              .el-x-bubble-footer {

                .end-action,
                .start-action {
                  display: flex;
                  gap: 10px;
                  align-items: center;
                  opacity: 0;
                  transition: opacity 0.2s ease;

                  .action-btn {
                    cursor: pointer;
                  }
                }
              }
            }

            // 鼠标悬停时显示footer
            &:hover {
              .el-x-bubble-content-wrapper {
                .el-x-bubble-footer {

                  .end-action,
                  .start-action {
                    opacity: 1;
                  }
                }
              }
            }
          }
        }
      }

      .chat-input {
        flex-shrink: 0;
        flex-direction: column;
        align-items: center;
        margin-top: auto;
        display: flex;
        position: -webkit-sticky;
        position: sticky;
        bottom: 0;

        .chat-input-container {
          max-width: 800px;
          flex-grow: 1;
          width: 100%;
          position: relative;
        }

        .chat-input-footer {
          font-size: 12px;
          color: #a3a3a3;
          margin: 6px 0;
          line-height: 14px;
        }
      }
    }
  }
}

// PC端小屏幕适配 (768px - 1024px) - 优化布局
@media (max-width: 1024px) and (min-width: 768px) {
  .dify-chat .dify-main {
    .chat-container {
      max-width: none;
    }
  }
}

// 移动端适配 (<768px)
@media (max-width: 767px) {
  .dify-chat {
    .mobile-header {
      display: flex;
    }

    .dify-main {
      flex: 1;

      // 隐藏PC端侧边栏
      .side-menu,
      .side-menu-collapsed {
        display: none;
      }

      .chat-container {
        width: 100%;
        max-width: none;
        margin: 0;

        .chat-header {
          display: none; // 移动端隐藏chat-header，使用mobile-header代替
        }

        .chat-content {
          padding: 16px 0;

          .chat-content-welcome {
            padding: 0;
          }
        }

        .chat-input {
          padding: 0 16px 16px;

          .chat-input-container {
            max-width: none;
          }
        }
      }
    }
  }
}

.thinking {
  display: flex;
  height: 32px;
  box-sizing: border-box;
  align-items: center;
  gap: 4px;
  padding: 2px 12px;
  border-width: 1px;
  border-style: solid;
  border-color: #0000001f;
  border-radius: 15px;
  cursor: pointer;
  font-size: 12px;
  color: black;
  transition: background-color 0.3s ease;

  // 未激活时的hover效果
  &:hover {
    background-color: #e0e4ed;
  }

  // 激活状态
  &--active {
    background-color: #dbeafe;
    color: #4d6bfe;
    border-color: #007aff26;
    padding: 3px 12px;
    font-weight: 700;

    // 激活时的hover效果
    &:hover {
      background-color: #c3daf8;
    }
  }
}
